package com.woniuxy.rms.dao;

import com.woniuxy.rms.pojo.Roles;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

public interface RolesMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Roles record);

    int insertSelective(Roles record);

    Roles selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Roles record);

    int updateByPrimaryKey(Roles record);

    /**
     * Description : 查询权限  <br/>
     * ChangeLog : 1. 创建 (2020/3/28 0028 下午 6:43 [Administrator]);
     * @param roleId
     * @return java.util.List<java.lang.String>
    */
    @Select("select perm.permission from roles r left join role_menu rm " +
            "on r.id = rm.role_id left join Menus m on m.id = rm.menu_id " +
            "left join permission perm on perm.id = m.permission_id where r.id = #{value}")
    List<String> findPermissionByRoleId(Integer roleId);

    @Select("select * from roles")
    List<Roles> findAll();

    /**
     * Description : 根据id批量删除角色  <br/>
     * ChangeLog : 1. 创建 (2020/3/24 0024 上午 11:23 [ChenGang]);
     * @param roleIds
     * @return void
    */
    void batchDelByIds(List<Integer> roleIds);

    /**
     * Description : 分页查询角色  <br/>
     * ChangeLog : 1. 创建 (2020/3/25 0025 下午 12:13 [ChenGang]);
     * @param currentPage 当前页
     * @param pageSize  条数
     * @return java.util.List<com.woniuxy.rms.pojo.Roles>
    */
    @Select("select roles.*,admin.admin_name from roles left join admin on admin.id = roles.admin_id ")
    List<Roles> findByPage(@Param("currentPage") Integer currentPage,@Param("pageSize") Integer pageSize);

    @Select("select * from roles where role = #{value}")
    List<Roles> findByRole(String role);

    void save(Roles roles);
}